Conversation
eigmax
reviewed
May 22, 2025
|
|
||
| let xonly_pk = XOnlyPublicKey::from(*pk_signer); | ||
| let funding_script = get_funding_script(&x_only_pk); | ||
| fill_dummy_taproot_witness( |
Contributor
There was a problem hiding this comment.
From my experience, we used to estimate the gas fee based on the tx base size and witness data, since we know all them in advance.
Given that:
Est fee = fee rate * (vsize + 10)
signature: 64-byte
vsize = vweight/4
vweight = tx_base_size * 3 + tx_total_size
tx_total_size ~= tx_base_size + signature + redeem_script + control_block
control_block_size (byte) = 1 + 32 + 32 × depth
let mut tx = build_spending_tx(
funding_tx.txid(),
0,
taproot_addr,
funding_tx.output[0].value,
);
// base_size is tx size with witness stripped. assume there are 3 signature.
let vsize = (tx.base_size() as u64 * 4 + (redeem_script.to_bytes().len() as u64 + 64 * 3 + 33))/4 + 10;
println!("spending tx size: {}", vsize);
tx.output[0].value = tx.output[0].value - fee_rate * vsize;
Contributor
There was a problem hiding this comment.
fee rate:
let estimate_smart_fee_result = rpc_client.estimate_smart_fee(6, None).unwrap();
let fee_rate = if let Some(fee_rate) = estimate_smart_fee_result.fee_rate {
fee_rate
} else {
// If you're on regtest, this may not work well (always returns null), so fallback to a constant (e.g., 5–10 sat/vB).
Amount::from_sat(5)
};
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.